"""
@Author : 合肥一元数智教育科技有限公司
@Date :  2025/3/19 10:53
@Description :  wx库中常见组件使用
1. 文本框  可输入  input
2.按钮
3.单选
4. 复选
4.下拉选
"""
import wx


# 按钮的事件回调函数  事件的回调函数 默认会传递一个事件参数
def btn_fn(event):
    # 获取input_info
    message = input_info.GetValue()
    # 清空文本框
    input_info.Clear()
    # 写入数据到 text_area
    # text_area.SetValue(message)
    text_area.AppendText(message + '\n')


# 单选框事件
def radio_fn(event):
    # 获取事件源
    event_object = event.GetEventObject()
    # 获取事件源标签
    label = event_object.GetLabel()
    print(label)


# 复选框事件
def check_box_fn(event):
    event_object = event.GetEventObject()
    label = event_object.GetLabel()
    # 获取复选框的选中状态  选中 True  否则 False
    is_checked = event_object.IsChecked()
    print(label, is_checked)


def choice_select_fn(event):
    # selected = choice_select.GetStringSelection()
    selected = event.GetString()
    print(selected)


if __name__ == '__main__':
    app = wx.App()
    frame = wx.Frame(None, title='常见组件', size=(500, 600), pos=(500, 100))

    # 面板
    panel = wx.Panel(frame, size=(500, 600))
    panel.SetBackgroundColour(wx.WHITE)
    # 展示面板
    panel.Show()
    # 添加按钮
    btn = wx.Button(panel, label='普通按钮', pos=(30, 30), size=(130, 30))
    # 绑定按钮的事件
    btn.Bind(wx.EVT_BUTTON, btn_fn)
    # 只读文本域 wx.TE_READONLY  只读
    text_area = wx.TextCtrl(panel, pos=(10, 80), size=(400, 100), style=wx.TE_READONLY | wx.TE_MULTILINE)
    # 输入框  wx.TE_MULTILINE  多行显示
    input_info = wx.TextCtrl(panel, pos=(10, 180), size=(400, 100), style=wx.TE_MULTILINE)

    # 单选框  radio  style=wx.RB_GROUP  分组
    radio_btn1 = wx.RadioButton(panel, label='男', pos=(30, 330), size=(30, 30), style=wx.RB_GROUP)
    radio_btn2 = wx.RadioButton(panel, label='女', pos=(80, 330), size=(30, 30))
    radio_btn3 = wx.RadioButton(panel, label='是', pos=(130, 330), size=(30, 30), style=wx.RB_GROUP)
    radio_btn4 = wx.RadioButton(panel, label='否', pos=(180, 330), size=(30, 30))

    # 绑定单选框事件
    radio_btn1.Bind(wx.EVT_RADIOBUTTON, radio_fn)
    radio_btn2.Bind(wx.EVT_RADIOBUTTON, radio_fn)
    radio_btn3.Bind(wx.EVT_RADIOBUTTON, radio_fn)
    radio_btn4.Bind(wx.EVT_RADIOBUTTON, radio_fn)

    # 渲染复选框
    check_box1 = wx.CheckBox(panel, label='选项1', pos=(30, 380), size=(60, 30))
    check_box2 = wx.CheckBox(panel, label='选项2', pos=(100, 380), size=(60, 30))
    check_box3 = wx.CheckBox(panel, label='选项3', pos=(170, 380), size=(60, 30))

    # 绑定复选框事件
    check_box1.Bind(wx.EVT_CHECKBOX, check_box_fn)
    check_box2.Bind(wx.EVT_CHECKBOX, check_box_fn)
    check_box3.Bind(wx.EVT_CHECKBOX, check_box_fn)

    # 渲染下拉选
    choice_select = wx.Choice(panel, pos=(30, 480), size=(100, 50), choices=["选项1", "选项2", "选项3", "选项4"])
    # 绑定事件
    choice_select.Bind(wx.EVT_CHOICE, choice_select_fn)

    frame.Show()
    app.MainLoop()
